package com.lxb.stock;

import java.util.*;

public class GStockInfo 
{	
	String id;
	String market;
	String price;
	String tradeTime;
	String c;
	String cp;
	
	public GStockInfo(String id, String market, String price, Date tradeTime, String c, String cp)
	{
		
	}
	
	public GStockInfo(String rawdata)
	{
		parseRawData(rawdata);
	}
	
	public String getId()
	{
		return id;
	}
	
	public String getPrice()
	{
		return price;
	}
	
	public String getC()
	{
		return c;
	}
	
	public String getCP()
	{
		return cp;
	}
	
	public String getTradeTime()
	{
		return tradeTime;
	}
	
	public String getMarket()
	{
		return market;
	}
	
	private void parseRawData(String rawData)
	{
		String data = rawData.substring(rawData.indexOf("{\n") + 2, rawData.indexOf("}") - 1);
		//System.out.println("data is " + data);
		StringTokenizer st = new StringTokenizer(data, "\"");
		String prevToken = null;
		while(st.hasMoreTokens())
		{
			String t = st.nextToken();
			//System.out.println("t:" + t);
			int index = t.indexOf(":"); 
			if ((index != 0)
				&& (index != 1))
			{
				prevToken = t;
				continue;
			}
			
			if (prevToken == null)
				continue;
			
			String value = st.nextToken();
			//System.out.println("value: " + value);
			if (prevToken.equals("id"))
			{
				
			}
			if (prevToken.equals("t"))
			{
				id = value;
			}
			if (prevToken.equals("e"))
			{
				market = value;
			}
			if (prevToken.equals("l"))
			{
				price = value;
			}
			if (prevToken.equals("l_cur"))
			{
				
			}
			if (prevToken.equals("ltt"))
			{
				tradeTime = value.substring(0, value.indexOf("CST") - 1 );
			}
			if (prevToken.equals("lt"))
			{
				
			}
			if (prevToken.equals("c"))
			{
				c = value;
			}
			if (prevToken.equals("cp"))
			{
				cp = value;
			}
			if (prevToken.equals("ccol"))
			{
				
			}
		
		}
		
	}
}
